from flask import Flask,request,send_from_directory
app = Flask(__name__)

#支持跨域访问
'''from flask_cors import *
CORS(app, supports_credentials=True)'''

@app.route("/")
def hello():
    return "Hello World!"

@app.route("/getTestGroupList", methods=['GET'])
def getTestGroupList():
	proj_id = int(request.args.get('proj_id'))
	page = int(request.args.get('page'))
	
@app.route("/genExcel", methods=['POST'])
def genExcel():
	data = request.form.get('data')
	if data:
		with open('test.txt','w') as wf:
			wf.write(data)
	return 'succeed'

@app.route("/genExcel", methods=['POST'])
#请求格式为json
def genExcel():
	data=json.loads(request.get_data().decode('utf-8'))['content']
	if data:
		with open('test.txt','w') as wf:
			wf.write(data)
	return 'succeed'

@app.route("/download/<filename>", methods=['GET'])
def download_file(filename):
    # 需要知道2个参数, 第1个参数是本地目录的path, 第2个参数是文件名(带扩展名)
    return send_from_directory('./download', filename, as_attachment=True)

if __name__ == '__main__':
	#from werkzeug.contrib.fixers import ProxyFix
	#app.wsgi_app = ProxyFix(app.wsgi_app)
	#pip install gunicorn
	#gunicorn -w 4 -b 0.0.0.0:5555 main:app
	app.debug=True
	app.run(host='0.0.0.0',port=5555)